<?php
session_start();
ini_set('display_errors',1);
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/class.admin.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/database.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/functions.php');
$admin= new admin();
$admin->canView($_SERVER['PHP_SELF']);
$gid=$_GET['gid'];
// where to pull from ?
$criteria=array('$pull'=>array('groups'=>$gid));
$f_criteria=array('groups'=>array('$in'=>array($gid)));


$data=new database();
$data->db(DATABASE);
$a=array('pages','users','admin_pages');
foreach($a as $p) {
$data->collection($p);
$data->criteria($criteria);
$data->updateMultiple($f_criteria);
}
$data->collection('groups');
$data->criteria(array('_id'=>new MongoId($gid)));
$data->remove();
$data->close();
?>
<script>
$("#groups-click").click();

</script>